<template>

  <div>
    <div>
      <el-input style="width: 180px; margin-right: 10px;" suffix-icon="Search" placeholder="请输入学生姓名"
                v-model="pageParam.param.stuName"></el-input>

      <el-input style="width: 180px; margin-right: 10px;" suffix-icon="Search" placeholder="请输入班级名"
                v-model="pageParam.param.className"></el-input>

      <el-button type="success" @click="clearAll" >重置</el-button>
      <el-button type="primary" @click="dialogFormVisible = true, daoru()">导入学生</el-button>
    </div>
    <el-table :data="data" ref="forData"
              :header-cell-style="{ background: '#f2f5fc', color: '#555555' }"
              border style="width: 1110px; margin-top: 10px; margin-bottom: 10px;">
      <el-table-column prop="stuNum" label="学号" width="120" />
      <el-table-column prop="stuName" label="学生姓名" width="180" />
      <el-table-column prop="claName" label="班级名称" width="180" />
      <el-table-column label="操作" width="180">
        <template #default="scope">
          <el-button type="success" size="small" @click="studentLearnData(scope)" >学习详情</el-button>
<!--          <el-button type="success" size="small" @click="studentLearnDataWork(scope)" >作业完成详情</el-button>-->

          <el-button  type="danger" size="small" @click="del(scope)">删除</el-button>

        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        v-model:current-page="pageParam.pageNum"
        v-model:page-size="pageParam.pageSize"
        :page-sizes="[2, 5, 10, 20]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
    />


    <el-dialog v-model="dialogFormVisible" title="学习情况">
      <el-table :data="stuApplyData">
        <el-table-column label="学生学号" prop="stuNum" />
        <el-table-column label="学生姓名" prop="stuName" />
        <el-table-column label="申请班级"   prop="claName" /> >
        <el-table-column label="时间" width="200" prop="createTime" />
        <el-table-column label="操作" width="180">
          <template #default="scope">
<!--            <el-button type="success" size="small" @click="studentLearnData(scope)" >学习详情</el-button>-->
            <el-button type="danger" size="small" @click="agree(scope)">同意</el-button>
            <el-button type="danger" size="small" @click="disagree (scope)">不同意</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>


  </div>

</template>

<script>
import {useLoginStateStore} from "../../store/storeLoginState.js";
import {Search} from "@element-plus/icons-vue";
import { reactive, ref } from 'vue'
import {ElMessage, ElMessageBox, ElNotification} from "element-plus";
export default {
  name: "StudentManage",
  setup(){
    const loginStateStore = useLoginStateStore()
    return {
      loginStateStore: loginStateStore
    }
  },
  data(){
    return{
      //分页查询学生数据
      pageParam:{
        pageSize:10,			//每页显示几条
        pageNum:1,				//当前页数
        param:{					//查询条件
          stuName:'',			//学生姓名
          className:'',		//班级名称
          teaNum:''  //登录者教师学号
        }
      },
      total:0,             		//查询到的条目
      data:[] ,//分页的数据
      stuApplyData:[],
      dialogFormVisible : ref(false),
    }
  },


  methods:{
    //删除
    del(scope){
      ElMessageBox.confirm(
          '请再次确认删除此学生',
          '警告',
          {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
          }
      )
          .then(() => {
            let  url = "/studyadmin/classes/delStuClass";
            _this.$axios.get(url, {params: {stuNum:stuNum}}).then(function (serverData) {
              if(serverData.data.code===0){
                _this.test();
                ElMessage({
                  type: 'success',
                  message: '删除成功',
                })
              }
            })

          })
          .catch(() => {
            ElMessage({
              type: 'info',
              message: '删除取消',
            })
          })

      let _this=this
      let stuNum=scope.row.stuNum

    },

    //同意申请
    agree(scope){
      let _this=this
      let url = "/studyadmin/teacher/agreeStuApply";
      let stuNum=scope.row.stuNum
      _this.$axios.get(url, {params: {stuNum:stuNum}}).then(function (serverData) {
        // _this.stuApplyData = serverData.data.data;
        if(serverData.data.code===0){
          _this.daoru()
          _this.test();
        }
        // console.log("***************",_this.stuApplyData)
      })
    },
    disagree(scope){

      let _this=this
      let url = "/studyadmin/teacher/disagreeStuApply";
      let stuNum=scope.row.stuNum
      _this.$axios.get(url, {params: {stuNum:stuNum}}).then(function (serverData) {
        // _this.stuApplyData = serverData.data.data;
        if(serverData.data.code===0){
          _this.daoru()
          _this.test();
        }
      })
    },
    //学生加入班级申请
    daoru(){
      let url = "/studyadmin/teacher/stuApply";
      let _this = this;
      // let  stuNum=window.sessionStorage.getItem("userNum")
      let teaNum=window.sessionStorage.getItem("userNum")
      _this.$axios.get(url, {params: {teaNum:teaNum}}).then(function (serverData) {
        _this.stuApplyData = serverData.data.data;
        console.log("***************",_this.stuApplyData)
      })

    },

    test() {		//查询 goods 数据方法
      let url = "/studyadmin/teacher/listInfoPageC";
      let _this = this;
      let teaNum = window.sessionStorage.getItem("userNum")
      _this.pageParam.param.teaNum=teaNum

      _this.$axios.post(url, _this.pageParam).then(function (serverData) {
        _this.total = serverData.data.total;
        _this.data = serverData.data.data;
        // console.log("***************",_this.data)
      })
    },
    handleSizeChange(val) {			//修改当前每页条目树
      this.pageParam.pageSize = val;
    },
    handleCurrentChange(val) {		//修改当前所在页数
      this.pageParam.pageNum = val;
    },
    //清空
    clearAll() {
      this.pageParam.param.stuName = '';
      this.pageParam.param.className = '';
      // this.pageParam.param.teaNum = '';
    },
    //学生学习详情
    studentLearnData(scope){
     		//学生xuehao
      this.$router.push({path:'learningMonitoring',
        query: {stuNum:scope.row.stuNum,claName:scope.row.claName,stuName:scope.row.stuName}})

    },

},
  watch:{
    pageParam:{			//当pageParam中参数发生变化时重新查询后端数据
      handler(newValue, oldValue) {
        this.test();
      },
      deep: true
    }
  },
  beforeMount() {
    this.test();
  },



}
</script>

<style scoped>

</style>
